Repository navigation
Add a refactoring between ?x and [<Struct>] ?x optional parameters - #20546
xperiandri wants to merge 9 commits into
Conversation
✅ Release notes checked
|
This comment has been minimized.
This comment has been minimized.
T-Gro
left a comment
There was a problem hiding this comment.
🤖🕵️ Please shorten the description using this guidance. Focus on the problem and why the change is needed, in simplified technical English. Leave the implementation inventory to the Files tab and retain necessary caveats.
?x and [<Struct>] ?x optional parameters
Covered casesConverts
Not offered
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fd24fc7 to
6080188
Compare
T-Gro
left a comment
There was a problem hiding this comment.
The diff is still way too big - apply the NoBloat instructions and CodeCompaction skill.
Especially the massive code comments would benefit not just with drastic reduction, but ideally with well named functions/arguments/bindings/types making the intention clear.
If a well named piece of code just tells what the comment says - delete the comment.
- This diff adds 22 new code comment lines and 2176 new code comment chars.
- Comments bypass the type system and become stale maintenance state. Keep only durable public contracts; express implementation intent through names, functions, active patterns, discriminated unions, and types.
f176a68 to
ed9ca77
Compare
|
Commits d40c554 (source) and c9643f6 (tests) apply the compaction: added comment lines 22 -> 1 and comment characters 2176 -> 123, the one left being the license header, with the explanations now carried by names such as |
… commenting them The doc comments of ConvertOptionalParameterDefaultValue.fs move into names: the Form cases FSharpOptional and DotNetOptional, fsharpCoreNameAt, IdentsAndLast, tryAnnotatedParameter, hasOnlyOptionalAttributes, tryShadowingLineSpan, whiteSpaceBeforeBody, passesMissingValueWhenOmitted, isUseInMemberBody and projectAndDependentsSupportStructOptionals. Only the license header stays. ComputeRefactoringsAsync nested nine levels of control flow. The actions are now built by actionsFor and the solution by changedSolution, so the provider nests three. tryForm and tryParameter go from four levels to two through tryDotNetOptional and searchResultAt. Repeated pieces are merged: tryGetSymbolUse serves the provider and isFSharpCoreSymbol, documentAction builds the two document actions, Range.rangeContainsPos replaces hand-written position comparisons and SingleIdent replaces isOperator. tryGetSymbolUse, isInFSharpCore and isFSharpCoreSymbol are the same text as in ConvertOptionalParameterStruct.fs of the optional parameter struct refactoring (PR dotnet#20546); the two pull requests keep their own copies. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Port of the dotnet#20546 compaction (feature/optional-parameter-struct-refactoring ed9ca77..c9643f6) to all-fixes: - Name the optional parameter conversion steps instead of commenting them - Parameterize the optional parameter conversion tests The refactoring's member lookup is the one call site of getSymbolUses; it keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Port of the dotnet#20546 compaction (feature/optional-parameter-struct-refactoring ed9ca77..c9643f6) to all-fixes: - Name the optional parameter conversion steps instead of commenting them - Parameterize the optional parameter conversion tests The refactoring's member lookup is the one call site of getSymbolUses; it keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Port of the dotnet#20546 compaction (feature/optional-parameter-struct-refactoring ed9ca77..c9643f6) to all-fixes: - Name the optional parameter conversion steps instead of commenting them - Parameterize the optional parameter conversion tests The refactoring's member lookup is the one call site of getSymbolUses; it keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Port of the dotnet#20546 compaction (feature/optional-parameter-struct-refactoring ed9ca77..c9643f6) to all-fixes: - Name the optional parameter conversion steps instead of commenting them - Parameterize the optional parameter conversion tests The refactoring's member lookup is the one call site of getSymbolUses; it keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Port of the dotnet#20546 compaction (feature/optional-parameter-struct-refactoring ed9ca77..c9643f6) to all-fixes: - Name the optional parameter conversion steps instead of commenting them - Parameterize the optional parameter conversion tests The refactoring's member lookup is the one call site of getSymbolUses; it keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
c9643f6 to
829ccb7
Compare
… commenting them The doc comments of ConvertOptionalParameterDefaultValue.fs move into names: the Form cases FSharpOptional and DotNetOptional, fsharpCoreNameAt, IdentsAndLast, tryAnnotatedParameter, hasOnlyOptionalAttributes, tryShadowingLineSpan, whiteSpaceBeforeBody, passesMissingValueWhenOmitted, isUseInMemberBody and projectAndDependentsSupportStructOptionals. Only the license header stays. ComputeRefactoringsAsync nested nine levels of control flow. The actions are now built by actionsFor and the solution by changedSolution, so the provider nests three. tryForm and tryParameter go from four levels to two through tryDotNetOptional and searchResultAt. Repeated pieces are merged: tryGetSymbolUse serves the provider and isFSharpCoreSymbol, documentAction builds the two document actions, Range.rangeContainsPos replaces hand-written position comparisons and SingleIdent replaces isOperator. tryGetSymbolUse, isInFSharpCore and isFSharpCoreSymbol are the same text as in ConvertOptionalParameterStruct.fs of the optional parameter struct refactoring (PR dotnet#20546); the two pull requests keep their own copies. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
?x and [<Struct>] ?x give the member body an option or a value option. The refactoring toggles the attribute, renames what keeps its type in the body (defaultArg, Option functions that do not return an option, match cases on the parameter) and rewrites ?x = value arguments at the call sites in the solution. Bodies that pass the parameter on or map it are refused. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…e of its section Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Some/None, defaultArg and Option.* in the member body are renamed only when they resolve to FSharp.Core; a shadowed name leaves the refactoring off. At call sites, a value built with a shadowed Some goes through ValueOption.ofOption instead of being renamed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review findings on the refactoring between `?x` and `[<Struct>] ?x`: - The names the conversion writes (`ValueSome`, `ValueOption.isSome`, `defaultValueArg` and their option counterparts) are checked where they are written: when user code shadows one, the member body is not offered the conversion, a call site keeps its value behind a conversion function, and that function is written with its full FSharp.Core name. - Converting to a value option needs F# 10 in every F# project that depends on the declaring one, because their call sites are rewritten too. - `[<param: Struct>] ?x` is a value option parameter, as it is for the compiler. - An option module function is renamed only when the parameter is its last argument, and `|>` only counts when it is the FSharp.Core operator. - A match clause that binds the parameter to a new name is not converted. - No action when another overload already has the converted signature. - A call of an instance member with explicit type arguments is rewritten. - Dropping `ValueOption.ofOption` at a call site keeps the comment after it and no longer overlaps the edits of a call nested in its argument. - The solution change is computed anew for every invocation of the action, so an invocation that was cancelled does not cancel the next one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The doc comments of ConvertOptionalParameterStruct.fs move into names: resolvesOnlyToFSharpCore, arityOfOptionKindIndependentFunction, tryEnclosingMember, tryRenamesOfUse, tryRenamesOfEveryUse, calleeEndsAt, isUseInMemberBody, otherParametersToOwnTypes, ownAsListedByEntity and projectAndDependentsSupportValueOptions. Only the license header stays. ComputeRefactoringsAsync nested eight levels of control flow. The action is now built by tryCreateAction and the solution by changedSolution, so the provider nests three. Repeated pieces are merged: tryGetSymbolUse serves the provider and isFSharpCoreSymbol, isConvertibleCase names the check two call sites spelled out, Range.rangeContainsPos replaces a hand-written position comparison and SingleIdent replaces isOperator. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The module header comes from one helper instead of being written into 45 strings. The six one-off conversion facts become named rows of the two conversion theories, and every row of the three theories gets a name, so a failure says which scenario it was. The caret is the first question mark of the source unless a row needs another marker. Every input and every expected result is kept: 36 cases before and after. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replaying the branch onto main left some files short of the branch's own content; this restores it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
829ccb7 to
5b9dec3
Compare
… commenting them The doc comments of ConvertOptionalParameterDefaultValue.fs move into names: the Form cases FSharpOptional and DotNetOptional, fsharpCoreNameAt, IdentsAndLast, tryAnnotatedParameter, hasOnlyOptionalAttributes, tryShadowingLineSpan, whiteSpaceBeforeBody, passesMissingValueWhenOmitted, isUseInMemberBody and projectAndDependentsSupportStructOptionals. Only the license header stays. ComputeRefactoringsAsync nested nine levels of control flow. The actions are now built by actionsFor and the solution by changedSolution, so the provider nests three. tryForm and tryParameter go from four levels to two through tryDotNetOptional and searchResultAt. Repeated pieces are merged: tryGetSymbolUse serves the provider and isFSharpCoreSymbol, documentAction builds the two document actions, Range.rangeContainsPos replaces hand-written position comparisons and SingleIdent replaces isOperator. tryGetSymbolUse, isInFSharpCore and isFSharpCoreSymbol are the same text as in ConvertOptionalParameterStruct.fs of the optional parameter struct refactoring (PR dotnet#20546); the two pull requests keep their own copies. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
5b9dec3 to
f38250f
Compare
… commenting them The doc comments of ConvertOptionalParameterDefaultValue.fs move into names: the Form cases FSharpOptional and DotNetOptional, fsharpCoreNameAt, IdentsAndLast, tryAnnotatedParameter, hasOnlyOptionalAttributes, tryShadowingLineSpan, whiteSpaceBeforeBody, passesMissingValueWhenOmitted, isUseInMemberBody and projectAndDependentsSupportStructOptionals. Only the license header stays. ComputeRefactoringsAsync nested nine levels of control flow. The actions are now built by actionsFor and the solution by changedSolution, so the provider nests three. tryForm and tryParameter go from four levels to two through tryDotNetOptional and searchResultAt. Repeated pieces are merged: tryGetSymbolUse serves the provider and isFSharpCoreSymbol, documentAction builds the two document actions, Range.rangeContainsPos replaces hand-written position comparisons and SingleIdent replaces isOperator. tryGetSymbolUse, isInFSharpCore and isFSharpCoreSymbol are the same text as in ConvertOptionalParameterStruct.fs of the optional parameter struct refactoring (PR dotnet#20546); the two pull requests keep their own copies. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
/azp run |
|
No pipelines are associated with this pull request. |
| let definitionChanges = | ||
| OptionalParameterConversion.definitionChanges sourceText parameter renames | ||
|
|
||
| CodeAction.Create(title, changedSolution document sourceText checkResults memberUse parameter definitionChanges, title)) |
There was a problem hiding this comment.
🤖🕵️ Shared state machine: a canceled preview cancels apply.
let c = cancellableTask { let! ct = CancellableTask.getCancellationToken ()
do! Task.Delay(300, ct) }
try (c (new CancellationTokenSource(50)).Token).Wait() with _ -> () // preview
(c CancellationToken.None).Wait() // apply: TaskCanceledException|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Offers
Ctrl+.on a member's optional parameter to switch it betweenoptionandvoption(F# 10).defaultArg,Optionfunctions andmatchcases on it in the body, and?x = valuearguments at call sites across the solution, are rewritten to match.Not offered when a use of the parameter would change type (passed on,
Option.map), for overrides, abstract slots and constructors, or when the file has a paired.fsi.🤖 Generated with Claude Code